#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;

struct lubao {
	int money, horse;
	bool operator < (const lubao &x) const {
		return money > x.money;
	}
} lu[10001];

struct guoguo {
	int horse;
	bool operator < (const guoguo &x) const {
		return horse < x.horse;
	}
} guo[10001];

int main() {
	int t;
	cin >> t;
	while (t--) {
		int n;
		cin >> n;
		for (int i = 1; i <= n; i++)
			cin >> lu[i].horse;
		for (int i = 1; i <= n; i++)
			cin >> lu[i].money;
		for (int i = 1; i <= n; i++)
			cin >> guo[i].horse;

		sort(guo + 1, guo + n + 1);
		sort(lu + 1, lu + n + 1);

		int money = 0;
		for (int i = 1; i <= n; i++) {
			for (int j = 1; j <= n; j++) {
				if (lu[j].horse != -1 && guo[i].horse > lu[j].horse) {
					money += lu[j].money;
					lu[j].horse = -1;
					lu[j].money = 0;
					break;
				}
			}
		}

		for (int i = 1; i <= n; i++)
			money -= lu[i].money;
		cout << money << endl;
	}
	return 0;
}

